
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;


public class NIOTransportClient {
	public static void main(String[] args) throws IOException, InterruptedException {
    	FileChannel can =  (new FileInputStream(args[0])).getChannel();
    	if (can.size() > Integer.MAX_VALUE) {
    		throw new RuntimeException();
    	}
    	ByteBuffer buff = ByteBuffer.allocate((int)can.size());
        long time = System.currentTimeMillis();
        SocketChannel channel = SocketChannel.open();
        channel.connect(new InetSocketAddress("192.168.1.106", 90));

        while (can.read(buff) != -1) {
            buff.flip();
            channel.write(buff);
            buff.clear();
        }
        System.out.println(System.currentTimeMillis() - time);
        can.close();
    }
}
